/**
 * date util
 * create by xai on 09/07/2018 1:46 PM
 */

// import moment from 'moment'

/**
 * 时间戳转日期，默认格式为 2018-07-09 13:48:11
 * @param ts int 时间戳，可传入字符串类型
 * @param sp 分隔符，默认 -
 */
export function timestamp2Date (ts, sp = '-') {
    typeof ts === 'string' ? parseInt(ts, 10) : ts
    let date = new Date(ts)
    let y = date.getFullYear()
    let m = date.getMonth() + 1
    let d = date.getDate()
    let h = date.getHours()
    let mm = date.getMinutes()
    let s = date.getSeconds()
    return y + '-' + isNeedAdd0(m) + '-' + isNeedAdd0(d) + ' ' + isNeedAdd0(h) + ':' + isNeedAdd0(mm) + ':' + isNeedAdd0(s)
  }
  
  function isNeedAdd0 (m) {
    return m < 10 ? '0' + m : m
  }
  